package com.wyp.design.pattern.creational.builder.v2;

/**
 * @author: yipeng.wang01@hand-china.com-25490
 * @TIME: 2019/12/31/11:31
 **/
public class Course {
    private String courseName;
    private String coursePTT;
    private String courseArticle;
    private String courseVideo;

    /**
     * 空参构造
     */
    public Course() {

    }

    public Course(CourseBuilder courseBuilder) {
        this.courseArticle = courseBuilder.courseArticle;
        this.courseName = courseBuilder.courseName;
        this.coursePTT = courseBuilder.coursePTT;
        this.courseVideo = courseBuilder.courseVideo;
    }

    @Override
    public String toString() {
        return "Course{" +
                "courseName='" + courseName + '\'' +
                ", coursePTT='" + coursePTT + '\'' +
                ", courseArticle='" + courseArticle + '\'' +
                ", courseVideo='" + courseVideo + '\'' +
                '}';
    }

    public static class CourseBuilder {

        private String courseName;
        private String coursePTT;
        private String courseArticle;
        private String courseVideo;

        CourseBuilder setCourseName(String courseName) {
            this.courseName = courseName;
            return this;
        }

        CourseBuilder setCoursePPT(String coursePPT) {
            this.coursePTT = coursePPT;
            return this;
        }

        CourseBuilder setCourseArticle(String courseArticle) {
            this.courseArticle = courseArticle;
            return this;
        }

        CourseBuilder setCourseVideo(String courseVideo) {
            this.courseVideo = courseVideo;
            return this;
        }

        //使用内部类进行将构建者与实体放在一起，这里使用实体的构造方法进行实例化实体，传入构建者实体
        public Course build() {
            return new Course(this);
        }

    }
}
